#include "data_global.h"
#include "fspwmbeeper.h"


extern pthread_mutex_t mutex_buzzer;
extern pthread_cond_t  cond_buzzer;
extern unsigned char  cmd_buzzer;
extern int buzzerfd;

// 蜂鸣器控制线程
void *pthread_buzzer(void *arg)
{
	printf("pthread_buzzer\n");
	while (1){
		pthread_mutex_lock(&mutex_buzzer);
		pthread_cond_wait(&cond_buzzer, &mutex_buzzer);

		if (cmd_buzzer == 0x51){
			//打开蜂鸣器
			ioctl(buzzerfd, PWM_ON);
		}else if (cmd_buzzer == 0x50){
			//关闭蜂鸣器
			ioctl(buzzerfd, PWM_OFF);
		}else{
			printf("cmd_buzzer error.\n");
		}

		pthread_mutex_unlock(&mutex_buzzer);
	}
}
